package com.aftersale.demo.entity;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
*@Author  空
*@Date    2023/10/23 20:22
*@Desc
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "com.aftersale.demo.entity.Result",description = "响应结果封装")
public class Result<T> {
    public static final String SUCCESS_CODE="200";
    public static final String ERROR_CODE="500";
    @ApiModelProperty(value = "响应码")
    private String code;
    @ApiModelProperty(value = "响应信息")
    private String msg;
    @ApiModelProperty(value = "响应数据")
    private T data;
    public static Result success(){
        return new Result(SUCCESS_CODE,"请求成功",null);
    }
    public static Result success(String msg){
        return new Result(SUCCESS_CODE,msg,null);
    }
    public static Result success(String msg,Object data){
        return new Result(SUCCESS_CODE,msg,data);
    }
    public static Result success(Object data){
        return new Result(SUCCESS_CODE,"请求成功",data);
    }
    public Result (String msg, T data){
        this.code=SUCCESS_CODE;
        this.msg=msg;
        this.data=data;
    }


    public static  Result error(){
        return new Result(ERROR_CODE,"系统错误，请联系管理员",null);
    }
    public static  Result error(String msg){
        return new Result(ERROR_CODE,msg,null);
    }
    public static  Result error(String code,String msg){
        return new Result(code,msg,null);
    }
}
